Skip to main content

Usage

Prerequisites

Signup on storage

Go to Chainsafe Storage if you haven’t created an account already.

Create an API key

  1. Go to settings and click on “Add API key”
  2. This will generate a key and a secret.

NOTE:

Store your secret somewhere safe like you would back up a private key for a crypto wallet. It won’t be displayed again in the API Key List of the settings page.

Storing NFT data

The process of storing NFT data is designed to be straightforward, allowing users to upload metadata along with files using the multipart/form-data format. Metadata pointing to files will be automatically uploaded to storage, with the final metadata JSON containing links to the uploaded files (gateway link). Nested and array values are also supported as follows:

  • If your metadata includes a key named "description", the form-data key will be the same, with the value as type text.
  • If your metadata includes a key named "image" and you prefer not to upload the image separately, you can simply attach the image file for that key.
  • If your metadata is nested, such as {"attributes" : {"class": "first edition"}}, you need to use the form-data key attributes.class.
  • If your metadata includes an array, such as {"attributes" : [{"trait_type": "class", "value": "first edition"}]}, you need to use the form-data key attributes[0].class.

Let's illustrate with an example. Suppose you want to upload metadata structured like this:

{
"attributes": [
{
"trait_type": "background",
"value": "white"
},
{
"trait_type": "logo",
"value": "Gaming"
}
],
"description": "ChainSafe Description",
"image": "ipfs://QmeAZgZXnz9ST2xm98Y3LfGb6pTcgducXnzfHubvt8C7Ri",
"name": "ChainSafe Name"
}

Your HTTP cURL request will resemble the following:

curl --location --request POST 'https://api.chainsafe.io/api/v1/nft?hash=blake2b-208' \
--header 'Authorization: Bearer <API_SECRET>' \
--form 'name="ChainSafe Name"' \
--form 'description="ChainSafe Description"' \
--form 'image=@"<PATH_TO_THE_FILE>"' \
--form 'attributes[0].trait_type="background"' \
--form 'attributes[0].value="white"' \
--form 'attributes[1].trait_type="logo"' \
--form 'attributes[1].value="Gaming"'

Retrieving NFT data

Upon making the above request, the response will include a CID (Content Identifier). Using the CID, data can be fetched directly from any public IPFS gateway. Alternatively, you can utilize ChainSafe's IPFS Gateway

The URL should be in this format:

https://{gateway URL}/ipfs/{CID}

With these steps, you have the necessary instructions to upload and retrieve your NFT's off-chain data using ChainSafe Storage.